home *** CD-ROM | disk | FTP | other *** search
- ;unsigned short add_subdirectory(tree_array,position,name);
- ; char *tree_array,*name;
- ; unsigned short position;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _tree_array_size:word
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _add_subdirectory
- _add_subdirectory proc near
- push bp ;
- mov bp,sp ;
- push di ;
- push si ;
- jmp short start ;jump over local data
- array_address dd ? ;
- start: cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,dword ptr[bp+4] ;get tree array address
- add di,21 ;start with array element 1
- mov word ptr cs:array_address,di
- mov word ptr cs:array_address+2,es
- mov bx,[bp+8] ;get Position
- lds si,dword ptr[bp+10];DS:SI pts to Name
- jmp short L00 ;
- L0: mov ax,[bp+4] ;NEAR case
- add ax,21 ;start with array element 1
- mov word ptr cs:array_address,ax
- mov word ptr cs:array_address+2,ds
- mov bx,[bp+6] ;get Position
- mov si,[bp+8] ;Name
- L00: mov dh,1 ;1 = Position out of range
- mov ax,_tree_array_size ;fetch _tree_array_size
- inc _tree_array_size ;will add a record
- cmp bx,ax ;in range?
- ja L6 ;quit if not
- inc dh ;2 = Name is null string
- sub cx,cx ;must get string length
- push si ;
- L1: cmp byte ptr[si],0 ;end of string?
- je L2 ;
- inc cx ;inc counter
- inc si ;inc pointer
- jmp short L1 ;
- L2: pop si ;now length in CX
- jcxz L6 ;quit if null
- mov dh,0 ;0 = no error
- push ax ;save position of new record
- les di,dword ptr cs:array_address ;DS:DI pts to tree array
- mov dl,21 ;21 bytes per record
- mul dl ;AX = offset of new record
- add di,ax ;point ES:DI to new record
- push di ;save record ptr
- inc cx ;move terminating null also
- cld ;
- rep movsb ;copy Name to record
- pop di ;restore record ptr
- mov es:[di+13],bx ;set Parent field
- mov es:[di+15],cx ;set Child to "none"
- mov es:[di+19],cx ;set Next to "none"
- lds si,dword ptr cs:array_address ;now DS:SI pts to tree array
- mov ax,bx ;move Position
- dec ax ;count from zero
- cmp ax,0ffffh ;test for root directory case
- jne L3 ;jump if not root
- mov ax,1 ;start with first record
- jmp short L4 ;jump ahead
- L3: mov dl,21 ;bytes per record
- mul dl ;
- add si,ax ;point to parent record
- mov ax,[si+15] ;get Child from parent
- or ax,ax ;see if child exists?
- jz L5 ;jump if not
- L4: mov bx,ax ;copy record number
- dec ax ;count records from zero
- lds si,dword ptr cs:array_address ;reload array address
- mov dl,21 ;bytes per record
- mul dl ;
- add si,ax ;
- mov ax,[si+19] ;test for next child
- or ax,ax ;
- jnz L4 ;loop till find last child
- mov word ptr es:[di+17],bx ;set new record's Prior
- pop ax ;position of new record
- inc ax ;count from 1
- mov [si+19],ax ;set Next field of Prior
- jmp short L6 ;
- L5: mov word ptr es:[di+17],0 ;set new record's Prior to 0
- pop ax ;position of new record
- inc ax ;count from 1
- mov [si+15],ax ;set Child field of Parent
- L6: pop ds ;
- mov _error_code,dh ;set _error_code
- pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _add_subdirectory endp
- _TEXT ENDS
- END